<?php
/**
 *   Joomdiet - administrator/components/views/importdata/view.html.php
 *   Author: Juan Dapena Paz (juan@bittingbits.com)
 *   Copyright (C) 2010 Bitting Bits S.L.
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.view');

class JoomdietViewImportData extends Jview
{
    function display($tpl=null)
    {
        // loading file uploader
        jimport('joomla.environment.uri' );
        $host = JURI::root();
 
        //add the links to the external files into the head of the webpage (note the 'administrator' in the path, which is not nescessary if you are in the frontend)
        $document =& JFactory::getDocument();
        $document->addScript($host.'administrator/components/com_joomdiet/assets/swfupload/swfupload.js');
        $document->addScript($host.'administrator/components/com_joomdiet/assets/swfupload/swfupload.queue.js');
        $document->addScript($host.'administrator/components/com_joomdiet/assets/swfupload/fileprogress.js');
        $document->addScript($host.'administrator/components/com_joomdiet/assets/swfupload/handlers.js');
        $document->addStyleSheet($host.'administrator/components/com_joomdiet/assets/swfupload/default.css');
        
        $session = & JFactory::getSession();
 
$swfUploadHeadJs ='
var swfu;
 
window.onload = function()
{
 
var settings = 
{
        //this is the path to the flash file, you need to put your components name into it
        flash_url : "'.$host.'administrator/components/com_joomdiet/assets/swfupload/swfupload/swfupload.swf",
 
        //we can not put any vars into the url for complicated reasons, but we can put them into the post...
        upload_url: "index.php",
        post_params: 
        {
                "option" : "com_joomdiet",
                "controller" : "filereceiver",
                "task" : "receivefile",
                //"id" : "/*.$myItemObject->id.*/",
                "'.$session->getName().'" : "'.$session->getId().'",
                "format" : "raw"
        }, 
        //you need to put the session and the "format raw" in there, the other ones are what you would normally put in the url
        file_size_limit : "5 MB",
        //client side file chacking is for usability only, you need to check server side for security
        file_types : "*.csv",
        file_types_description : "All Files",
        file_upload_limit : 1,
        file_queue_limit : 1,
        custom_settings : 
        {
                progressTarget : "fsUploadProgress",
                cancelButtonId : "btnCancel"
        },
        debug: false,
 
        // Button settings
        button_image_url: "'.$host.'administrator/components/com_mycomponent/swfupload/images/TestImageNoText_65x29.png",
        button_width: "85",
        button_height: "29",
        button_placeholder_id: "spanButtonPlaceHolder",
        button_text: \'<span class="theFont">Choose Files</span>\',
        button_text_style: ".theFont { font-size: 13; }",
        button_text_left_padding: 5,
        button_text_top_padding: 5,
 
        // The event handler functions are defined in handlers.js
        file_queued_handler : fileQueued,
        file_queue_error_handler : fileQueueError,
        file_dialog_complete_handler : fileDialogComplete,
        upload_start_handler : uploadStart,
        upload_progress_handler : uploadProgress,
        upload_error_handler : uploadError,
        upload_success_handler : uploadSuccess,
        upload_complete_handler : uploadComplete,
        queue_complete_handler : queueComplete     // Queue plugin event
};
swfu = new SWFUpload(settings);
};
 
';
 
//add the javascript to the head of the html document
$document->addScriptDeclaration($swfUploadHeadJs);
    
        JToolBarHelper::title(JText::_('COM_JOOMDIET_IMPORT_DATA'));
        
        parent::display($tpl);
    }
}
?>
